<?php
$smarty->configLoad($lang . '/donate.module.php');
$language = parse_ini_file($lang . '/breadcrumb.module.php', true);
$breadcrumb = $language['donate'];
/*
 * Get Total Earning
 */
$sql = 'SELECT SUM(amount) FROM '.DB_CMS.'.module_donate';
$dbh = $connection->prepare($sql);
$dbh->execute();
$row = $dbh->fetch(PDO::FETCH_ASSOC);
$total_earnings = array_sum($row);
$smarty->assign('total_earnings', $total_earnings);


/*
 * Get Donators
 */
$value = '';
$sql = 'SELECT * FROM '.DB_CMS.'.module_donate ORDER BY id DESC LIMIT 6';
$dbh = $connection->prepare($sql);
$dbh->execute();
$i = 0;
$user = new user;
foreach($dbh->fetchAll(PDO::FETCH_ASSOC) as $row) {
	if($row['amount'] >= 1) {
		$color = '#9DD1A9';
	} else {
		$color = '#CF9D9D';
	}
	
    $value[] = $row;
	$value[$i]['color'] = $color;
    $value[$i]['username'] = $user->getName($row['userID']);
    $value[$i]['adminname'] = $user->getName($row['admin']);
    $i++;
}
$smarty->assign('value', $value);

$template = 'donate/index.tpl';
?>
 